package com.ruoyi.personnel.management.nation.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.management.nation.domain.NationCond;
import com.ruoyi.personnel.management.nation.domain.NationDomain;
import com.ruoyi.personnel.management.nation.service.INationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 民族信息
 * 视图层
 */
@RestController
@RequestMapping("/personnel/nation")
@Api(value = "民族信息模块", tags = "民族信息接口")
public class NationController extends BaseController {
    @Autowired
    private INationService nationService;

    /**
     * 获取民族信息列表
     * @param cond 搜索条件
     * @return
     */
    @ApiOperationSupport(includeParameters = {"NationCond.nationName"})
    @ApiOperation(value = "获取民族信息列表",notes = "查询所有民族信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody NationCond cond) {
        startPage();
        List<NationDomain> nationList = nationService.selectNationList(cond);
        return getDataTable(nationList);
    }

    /**
     * 新增民族信息
     * @param nation
     * @return
     */
    @ApiOperation(value = "新增民族信息", notes = "新增民族信息")
    @ApiImplicitParam(name = "nation", value = "新增民族信息", dataType = "NationDomain")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody NationDomain nation) {
        return toAjax(nationService.insertNation(nation));
    }

    /**
     * 修改民族信息
     *
     * @param nation
     * @return
     */
    @ApiOperation(value = "修改民族信息", notes = "修改民族信息")
    @ApiImplicitParam(name = "nation", value = "修改民族信息", dataType = "NationDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody NationDomain nation) {
        return toAjax(nationService.updateNation(nation));
    }

    /**
     * 删除民族信息
     * 仅修改删除标志位
     *
     * @param nation
     * @return
     */
    @ApiOperation(value = "删除民族信息", notes = "删除民族信息,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody NationDomain nation) {
        return toAjax(nationService.updateNationDeleteFlag(nation));
    }
}
